package com.isdepci.project.carbon.controller;

import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.framework.web.page.TableDataInfo;
import com.isdepci.project.carbon.domain.BDirectRelease;
import com.isdepci.project.carbon.domain.param.WeatherDataExcel;
import com.isdepci.project.carbon.service.IBDirectReleaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 直接释放Controller
 *
 * @author isdepci
 * @date 2025-03-29
 */
@RestController
@RequestMapping("/direct/release")
public class BDirectReleaseController extends BaseController
{
    @Autowired
    private IBDirectReleaseService bDirectReleaseService;



    /**
     * 直接释放计算
     */
    @GetMapping("/calDirectRelease")
    public AjaxResult calDirectRelease(@RequestParam Long projectId) {
        return bDirectReleaseService.calDirectRelease(projectId);
    }

    /**
     * 查询直接释放列表
     */
    //  @PreAuthorize("@ss.hasPermi('direct:release:list')")
    @GetMapping("/list")
    public TableDataInfo list(BDirectRelease bDirectRelease)
    {
        startPage();
        List<BDirectRelease> list = bDirectReleaseService.selectBDirectReleaseList(bDirectRelease);
        return getDataTable(list);
    }

    /**
     * 导出直接释放列表
     */
    //  @PreAuthorize("@ss.hasPermi('direct:release:export')")
    @Log(title = "直接释放", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BDirectRelease bDirectRelease)
    {
        List<BDirectRelease> list = bDirectReleaseService.selectBDirectReleaseList(bDirectRelease);
        ExcelUtil<BDirectRelease> util = new ExcelUtil<BDirectRelease>(BDirectRelease.class);
        return util.exportExcel(list, "release");
    }

    /**
     * 上传保存数据
     * @param excel
     * @return
     */
    @PostMapping("/changeData")
    public AjaxResult changeDataByProjectId(@RequestBody WeatherDataExcel excel) {
        return bDirectReleaseService.changeDataByProjectId(excel);
    }

    /**
     * 获取直接释放详细信息
     */
    //  @PreAuthorize("@ss.hasPermi('direct:release:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bDirectReleaseService.selectBDirectReleaseById(id));
    }

    /**
     * 新增直接释放
     */
    //  @PreAuthorize("@ss.hasPermi('direct:release:add')")
    @Log(title = "直接释放", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BDirectRelease bDirectRelease)
    {
        return toAjax(bDirectReleaseService.insertBDirectRelease(bDirectRelease));
    }

    /**
     * 修改直接释放
     */
    //  @PreAuthorize("@ss.hasPermi('direct:release:edit')")
    @Log(title = "直接释放", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BDirectRelease bDirectRelease)
    {
        return toAjax(bDirectReleaseService.updateBDirectRelease(bDirectRelease));
    }

    /**
     * 删除直接释放
     */
    //  @PreAuthorize("@ss.hasPermi('direct:release:remove')")
    @Log(title = "直接释放", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bDirectReleaseService.deleteBDirectReleaseByIds(ids));
    }
}
